# json  是一种轻量级的数据交换标准
# python  --> json  --> js
# xml  json存储文档更小, 解析速度更快

# post请求

import urllib.request
import urllib.parse

url = 'https://fanyi.baidu.com/sug'

data = {
    'kw': 'car'
}

# post请求必须要进行编码并且进行encode方法的调用
data = urllib.parse.urlencode(data).encode('utf-8')

headers = {

    'User-Agent': 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50',
    'Cookie': 'BIDUPSID=050884BF79605B3FE5B441130814BD2B; PSTM=1600135523; BAIDUID=050884BF79605B3FB4E3B4F336CDFE50:FG=1; BD_UPN=12314753; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; sug=3; sugstore=1; ORIGIN=0; bdime=0; BDUSS=0J0QnVyV2lMMFNEMEtmRWpRLWdTWlZ4ZzI5Wkt0YXpKZERVNUhWcEE2MGJGb2hmRVFBQUFBJCQAAAAAAAAAAAEAAAAPfeKmsK7C~cXctcTO2rnqMwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABuJYF8biWBfT; BDUSS_BFESS=0J0QnVyV2lMMFNEMEtmRWpRLWdTWlZ4ZzI5Wkt0YXpKZERVNUhWcEE2MGJGb2hmRVFBQUFBJCQAAAAAAAAAAAEAAAAPfeKmsK7C~cXctcTO2rnqMwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABuJYF8biWBfT; BD_HOME=1; BDRCVFR[feWj1Vr5u3D]=I67x6TjHwwYf0; delPer=0; BD_CK_SAM=1; PSINO=3; COOKIE_SESSION=8131_0_8_0_15_7_1_0_5_4_2_3_0_0_1_0_1600250890_0_1600259020%7C9%230_0_1600259020%7C1; BDRCVFR[dG2JNJb_ajR]=mk3SLVN4HKm; BDRCVFR[-pGxjrCMryR]=mk3SLVN4HKm; BDRCVFR[tox4WRQ4-Km]=mk3SLVN4HKm; BDRCVFR[CLK3Lyfkr9D]=mk3SLVN4HKm; H_PS_645EC=2095Q1TdarCNVRr9ilYOnHk51HYr7VOda%2B%2B5r2jTHRuMltuw3coHrV%2FI%2Fyg; H_PS_PSSID=7540_32617_1439_31253_7609_7552_7608_32116_32718_22160; BDSVRTM=0'
}
# post请求的参数 需要请求对象的定制  post请求的参数不需要和url进行拼接
# 会自动将参数添加到请求体中
request = urllib.request.Request(url=url, headers=headers, data=data)
respons = urllib.request.urlopen(request)
content = respons.read().decode('utf-8')
print(content)
